<template>
	<view class="menu_content">
		<view class="stu_tel_list">
			<view class="stu_tel_item" @tap="call(stuEmergencyPhone1)">
				<image style="top: 12px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/police.png"></image>
				<image style="top: 35px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/telIcon.png"></image>
				<view class="stu_tel_item_span">Police Station</view>
				<view class="stu_tel_item_span">{{ stuEmergencyPhone1 }}</view>
			</view>
			<view class="stu_tel_item" @tap="call(fatherPhone)">
				<image style="top: 12px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/family.png"></image>
				<image style="top: 35px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/telIcon.png"></image>
				<view class="stu_tel_item_span">Relatives</view>
				<view class="stu_tel_item_span">{{ fatherPhone }}</view>
			</view>
			<view class="stu_tel_item" @tap="call(guarPhone)">
				<image style="top: 12px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/jianhuren.png"></image>
				<image style="top: 35px;left: 18px;" class="stu_tel_item_icon" src="../../static/img/telIcon.png"></image>
				<view class="stu_tel_item_span">Guardian</view>
				<view class="stu_tel_item_span">{{ guarPhone }}</view>
			</view>
		</view>
	</view>
</template>

<script>
import otherApi from '../../api/otherApi.js';
import utils from '../../api/utils.js';
export default {
	data() {
		return {
			stuEmergencyPhone1: '',
			guarPhone: '',
			fatherPhone: ''
		};
	},
	methods: {
		call(num) {
			uni.makePhoneCall({
				phoneNumber: num,
				success(res) {
					console.log(res);
				}
			});
		}
	},
	async onShow() {
		let token = '';
		let userId = '';
		uni.getStorage({
			key: 'token',
			success(res) {
				token = res.data;
			}
		});

		uni.getStorage({
			key: 'userInfo',
			success(res) {
				userId = res.data.userId;
			}
		});

		let getstu = await otherApi.getStu('user/getStu', { userId: userId }, token);
		this.stuEmergencyPhone1 = getstu.body.stuEmergencyPhone1;
		this.guarPhone = getstu.body.guarPhone;
		this.fatherPhone = getstu.body.fatherPhone;
		console.log(getstu);
		if (utils.userType == '学生' && utils.platform == 'android') {
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				async success(res) {
					let Position = {};
					Position = {
						address: (res.address.country + res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum).replace(
							/undefined/g,
							''
						),
						latitude: res.latitude,
						longitude: res.longitude
					};
					let savePosition = await otherApi.savePosition('position/savePosition', Position, token);
				}
			});
			setInterval(async () => {
				let Position = {};
				uni.getLocation({
					type: 'wgs84',
					geocode: true,
					async success(res) {
						let Position = {};
						Position = { 
							address: (res.address.country + res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum).replace(
								/undefined/g,
								''
							),
							latitude: res.latitude,
							longitude: res.longitude
						};
						await otherApi.savePosition('position/savePosition', Position, token);
					}
				});
			}, 900000);
		}
	}
};
</script>

<style scoped>
.menu_content {
	width: 100%;
}

.stu_tel_list {
	width: 100%;
	padding: 20px 30px;
	box-sizing: border-box;
}

.stu_tel_item {
	width: 100%;
	padding: 5px;
	height: 65px;
	border-bottom: solid 1px #dfdfdf;
	box-sizing: border-box;
	color: #666;
	position: relative;
	align-items: center;
	background: #f3b44b;
	margin-bottom: 5px;
	border-radius: 5px;
	color: #fff;
}

.stu_tel_item image {
	width: 30px;
	height: 30px;
	margin-right: 15px;
}

.stu_tel_item view {
	color: #0faeff;
}
.stu_tel_item .stu_tel_item_span {
	display: block;
	font-size: 14px;
	margin-left: 40px;
	color: #fff;
	margin-bottom: 5px;
	margin-top: 5px;
}

.stu_tel_item .stu_tel_item_icon {
	position: absolute;
	width: 15px;
	height: 18px;
}
</style>
